<template>
  <div class="box-main">
    <div class="box-content flex-center-between">
      <div class="flex-center box-box-content-price">
        <span>2024年1月</span>
        <img class="box-content-arrow-down" src="@/assets/images/IncomeDetails/icon3.png" alt="" />
      </div>
      <div class="flex-end box-content-price">
        <span class="box-content-price-symbol">￥</span>
        <span>3456.75</span>
      </div>
      <img class="box-content-img" src="@/assets/images/IncomeDetails/icon1.png" alt="" />
    </div>
    <div class="card">
      <div class="card-tilte">收益对比</div>
      <div id="myEcharts" style="width: 100%; height: 61.55vw;"></div>
    </div>
  </div>
</template>
<script setup>
import * as echarts from 'echarts';
import { onMounted, onUnmounted } from 'vue';


const initEcharts = () => {
  const myChart = echarts.init(document.getElementById('myEcharts'));

  const option = {
    backgroundColor: 'transparent',
    legend: {
      show: false
    },
    tooltip: {
      show: false,
      trigger: 'item',
    },
    grid: {
      top: '3%',
      left: '3%',
      right: '3%',
      bottom: '15%',
    },
    xAxis: [
      {
        type: 'category',
        data: ['1月', '1月', '1月', '1月', '12月\n2023年', '1月\n2024年', '2月'],
        axisTick: {
          show: false // 是否显示坐标轴轴线
        },
        axisLabel: {
          color: '#666666',
          fontSize: 12,
          interval: 0,
        },
        splitLine: {
          show: false
        },
        boundaryGap: true,
        axisLine: {
          show: false,
        }
      },
    ],
    yAxis: [
      {
        type: 'value',

        show: false,
      }
    ],
    series: [
      {
        name: '',
        type: 'bar',
        barMaxWidth: 10,
        zlevel: 10,
        data: [160, 230, 265, 150, 220, 170, 190],
        label: {
          show: true,
          position: 'top',
          color: '#DC376B',
          fontSize: 12
        },
        itemStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 1,
            y2: 1,
            colorStops: [{
              offset: 0,
              color: 'rgba(231, 22, 107, 1)'
            }, {
              offset: 1,
              color: 'rgba(231, 22, 107, 0)'
            }]
          },
          borderRadius: [30, 30, 0, 0],
        },
      }
    ]
  };

  myChart.setOption(option)
  // 响应式resize
  const resizeHandler = () => myChart.resize()
  window.addEventListener('resize', resizeHandler)
}

onMounted(() => {
  initEcharts()
})

onUnmounted(() => {
  window.removeEventListener('resize', resizeHandler)
})
</script>
<style lang="scss" scoped>
.box-main {
  width: 100vw;
  height: 100vh;
  background: #FBEBF0;
  display: flex;
  flex-direction: column;

  .flex {
    display: flex;
  }

  .flex-center {
    display: flex;
    align-items: center;
  }

  .flex-center-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .box-content {
    padding: 5.64vw 3.08vw 7.44vw;
    font-family: PingFang SC, PingFang SC;
    position: relative;

    .box-box-content-price {
      font-weight: normal;
      font-size: 4.1vw;
      color: #333333;
      line-height: 5.64vw;
    }

    .box-content-arrow-down {
      width: 2.31vw;
      height: 2.31vw;
      display: block;
      margin-left: 0.77vw;
    }

    .box-content-price {
      font-weight: 500;
      font-size: 6.15vw;
      color: #DC376B;

      .box-content-price-symbol {
        font-size: 4.62vw;
        line-height: 4.36vw;

      }
    }

    .box-content-img {
      position: absolute;
      width: 29.49vw;
      height: 29.49vw;
      display: block;
      left: 28.97vw;
      top: 0.77vw;
    }
  }

  .card {
    background: #FFFFFF;
    border-radius: 2.56vw 2.56vw 0vw 0vw;
    padding: 3.59vw 3.08vw;
    flex: 1;

    .card-tilte {
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      font-size: 4.1vw;
      color: #333333;
      line-height: 5.64vw;
    }
  }
}
</style>